package cc.rengu.redp.bizimpl.csmc.service.impl;

import cc.rengu.igas.bomp.facade.BompManualAdjustAcctService;
import cc.rengu.igas.bomp.facade.request.ManualAdjustmentRequest;
import cc.rengu.igas.bomp.facade.response.ManualAdjustmentResponse;
import cc.rengu.igas.bomp.facade.result.Result;
import cc.rengu.redp.bizimpl.csmc.dao.ReconErrTxnMapper;
import cc.rengu.redp.bizimpl.csmc.domain.ReconErrTxn;
import cc.rengu.redp.bizimpl.csmc.service.IReconErrTxnService;
import cc.rengu.redp.bizimpl.csmc.vo.ReconErrTxnVO;
import cc.rengu.redp.bizimpl.enums.BizDataAuditStatusEnum;
import cc.rengu.redp.bizimpl.enums.BizOprEnum;
import cc.rengu.redp.bizimpl.enums.BompTxnNumEnum;
import cc.rengu.redp.bizimpl.enums.PageOptFlagEnum;
import cc.rengu.redp.bizimpl.upmp.common.BusinessContainer;
import cc.rengu.redp.bizimpl.upmp.domain.BizTmp;
import cc.rengu.redp.bizimpl.upmp.domain.UpmpPrivilegeCheck;
import cc.rengu.redp.bizimpl.upmp.service.IBizHisService;
import cc.rengu.redp.bizimpl.upmp.service.IBizTmpService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpPrivilegeCheckService;
import cc.rengu.redp.bizimpl.upmp.service.IUpmpSysParamService;
import cc.rengu.redp.bizimpl.upmp.vo.UpmpUserInfoVO;
import cc.rengu.redp.bizimpl.utils.Common;
import cc.rengu.redp.bizimpl.utils.CommonUtils;
import cc.rengu.redp.bizimpl.utils.DateUtils;
import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.common.utils.SortUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author guohaocong
 */
@Service
@Slf4j
public class ReconErrTxnServiceImpl extends ServiceImpl<ReconErrTxnMapper, ReconErrTxn> implements IReconErrTxnService {

    @Autowired
    private IUpmpSysParamService upmpSysParamService;
    @Autowired
    private IUpmpPrivilegeCheckService authPrivilegeCheckService;
    @Autowired
    private IBizTmpService bizTmpService;
    @Autowired
    private IBizHisService bizHisService;

    /**
     * 虚拟账户对账不平列表查询
     * @param request
     * @param reconErrTxn
     * @return
     */
    @Override
    public IPage<ReconErrTxn> findPage(QueryRequest request, ReconErrTxn reconErrTxn) {
        // 当前登录用户
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isBlank(reconErrTxn.getInstId())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, user.getInstId());
        } else {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, reconErrTxn.getInstId());
        }
        if (!StringUtils.isBlank(reconErrTxn.getBatchDate())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getBatchDate, reconErrTxn.getBatchDate());
        }
        if (!StringUtils.isBlank(reconErrTxn.getReconRslt())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getReconRslt, reconErrTxn.getReconRslt());
        }
        if (!StringUtils.isBlank(reconErrTxn.getAdjustStatus())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getAdjustStatus, reconErrTxn.getAdjustStatus());
        }
        if (!StringUtils.isBlank(reconErrTxn.getCsmcBizType())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getCsmcBizType, reconErrTxn.getCsmcBizType());
        }
        lambdaQueryWrapper.eq(ReconErrTxn::getBizProdType, "47");
        Page<ReconErrTxn> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        Page<ReconErrTxn> page1 = this.page(page, lambdaQueryWrapper);
        List<ReconErrTxn> txnList = page1.getRecords();
        List<ReconErrTxn> list = null;
        for (ReconErrTxn txn : txnList) {
            String primaryKey = txn.getPrimaryKey();
            String acctSeqNum = this.baseMapper.selectacctSeqNum(primaryKey);
            if (StringUtils.isNotBlank(acctSeqNum)) {
                txn.setAcctSeqNum(acctSeqNum);
            }
            list = new ArrayList<>();
            list.add(txn);
        }
        page1.setTotal(list.size());
        return page1.setRecords(list);
    }

    /**
     *营销对账不平列表查询
     * @param request
     * @param reconErrTxn
     * @return
     */
    @Override
    public IPage<ReconErrTxn> SelectMarketingList(QueryRequest request, ReconErrTxn reconErrTxn) {
        // 当前登录用户
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isBlank(reconErrTxn.getInstId())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, user.getInstId());
        } else {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, reconErrTxn.getInstId());
        }
        if (!StringUtils.isBlank(reconErrTxn.getBatchDate())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getBatchDate, reconErrTxn.getBatchDate());
        }
        if (!StringUtils.isBlank(reconErrTxn.getReconRslt())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getReconRslt, reconErrTxn.getReconRslt());
        }
        if (!StringUtils.isBlank(reconErrTxn.getAdjustStatus())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getAdjustStatus, reconErrTxn.getAdjustStatus());
        }
        if (!StringUtils.isBlank(reconErrTxn.getCsmcBizType())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getCsmcBizType, reconErrTxn.getCsmcBizType());
        }
        lambdaQueryWrapper.eq(ReconErrTxn::getBizProdType, "45");
        Page<ReconErrTxn> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        Page<ReconErrTxn> page1 = this.page(page, lambdaQueryWrapper);
        page1.getRecords().stream().filter(reconErrTxn1 -> Double.valueOf(reconErrTxn1.getTransAmt()) - Double.valueOf(reconErrTxn1.getRealPayAmt()) >= 0)
                .forEach(reconErrTxn1 -> reconErrTxn1.setRemark5(String.valueOf(Double.valueOf(reconErrTxn1.getTransAmt()) - Double.valueOf(reconErrTxn1.getRealPayAmt()))));
        return page1;

    }

    /**
     * 通道对账不平列表查询
     * @param request
     * @param reconErrTxn
     * @return
     */
    @Override
    public IPage<ReconErrTxn> SelectChannelsList(QueryRequest request, ReconErrTxn reconErrTxn) {
        // 当前登录用户
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isBlank(reconErrTxn.getInstId())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, user.getInstId());
        } else {
            lambdaQueryWrapper.eq(ReconErrTxn::getInstId, reconErrTxn.getInstId());
        }
        if (!StringUtils.isBlank(reconErrTxn.getBatchDate())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getBatchDate, reconErrTxn.getBatchDate());
        }
        if (!StringUtils.isBlank(reconErrTxn.getReconRslt())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getReconRslt, reconErrTxn.getReconRslt());
        }
        if (!StringUtils.isBlank(reconErrTxn.getAdjustStatus())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getAdjustStatus, reconErrTxn.getAdjustStatus());
        }
        if (!StringUtils.isBlank(reconErrTxn.getCsmcBizType())) {
            lambdaQueryWrapper.eq(ReconErrTxn::getCsmcBizType, reconErrTxn.getCsmcBizType());
        }
        lambdaQueryWrapper.ne(ReconErrTxn::getBizProdType, "45").ne(ReconErrTxn::getBizProdType, "47");
        Page<ReconErrTxn> page = new Page<>();
        SortUtil.handlePageSort(request, page, true);
        return this.page(page, lambdaQueryWrapper);

    }


    @Override
    public void saveData(String menuId, String oprMenuName, ReconErrTxnVO reconErrTxnVO, String webNextUrl, String chkMenuName) throws RedpException {
        String flag = reconErrTxnVO.getOptFlag();
        String primaryKey = reconErrTxnVO.getPrimaryKey();
        String lastUpddt = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
        UpmpUserInfoVO user = CommonUtils.getCurrentUser(upmpSysParamService);
        String uuid = CommonUtils.getUUID();
        String Status = "N";
        if (PageOptFlagEnum.OPT_FLAG_UPDATE.getType().equals(flag)) {  //修改
//            String substring = chkMenuName.substring(chkMenuName.lastIndexOf(":")+1, chkMenuName.length());
            //校验权限，是否需要审核
            UpmpPrivilegeCheck privilegeCheck = authPrivilegeCheckService.getPrivilegeCheckByPrivilegeCode(reconErrTxnVO.getInstId(), "ReconerrTxn:edit");
            ReconErrTxn reconErrTxn = byOrigkey(primaryKey);
            //备份正式表数据
            ReconErrTxn reconerrtxnOld = new ReconErrTxn();
            BeanUtils.copyProperties(reconErrTxn, reconErrTxnVO);
            reconErrTxnVO.setAuditOprId(user.getId());
            reconErrTxnVO.setUpdateTime(lastUpddt);

            //判断是否需要审核
            if (null != privilegeCheck && BusinessContainer.YES.equals(privilegeCheck.getChecked())) {
                //修改正式表的审核状态
//                reconerrTxnDao.updateReconerrTxnEntry(primaryKey, user.getAuthUid(), lastUpddt, BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType(), lastUpddt);
                LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(ReconErrTxn::getPrimaryKey, primaryKey);
                ReconErrTxn txnUpdate = new ReconErrTxn();
                txnUpdate.setAuditOprId(user.getId());
                txnUpdate.setUpdateTime(lastUpddt);
                txnUpdate.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType());
                txnUpdate.setUpdateTime(lastUpddt);
                this.update(txnUpdate, lambdaQueryWrapper);

                reconErrTxnVO.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType());
                BeanUtils.copyProperties(reconErrTxnVO, reconErrTxn);
                //修改正式表调账状态为调账中 审核状态为修改待审核
                BizTmp biztmp = bizTmpService.getBizTmpByUniqueKey(user.getInstId(), "T_E_RECON_ERR_TXN", primaryKey);
                if (biztmp != null) {
                    biztmp.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_CHECKING.getType());
                    biztmp.setBizStatus("00");
                    biztmp.setLastUpdateTime(lastUpddt);
                    biztmp.setLastOprId(user.getId());
                    biztmp.setOprMenuName(chkMenuName);
                    bizTmpService.save(biztmp);
                } else {
                    BizTmp tmp = new BizTmp();
                    String bizData = JSON.toJSONString(reconErrTxnVO);
                    if (bizData.length() > 12000) {
                        throw new RedpException("业务数据过长，请联系管理员！");
                    }
                    String bizData1;
                    String bizData2 = "";
                    String bizData3 = "";
                    if (bizData.length() > 4000) {
                        bizData2 = bizData.substring(0, 3999);
                        bizData3 = bizData.substring(4000);
                    } else {
                        bizData2 = bizData;
                    }
                    if (bizData3.length() > 4000) {
                        throw new RedpException("业务数据过长，请联系管理员！");
                    }
                    tmp.setBizData1(primaryKey);
                    tmp.setBizData2(bizData2);
                    tmp.setBizData3(bizData3);
                    tmp.setBizOpr(BizOprEnum.OPR_UPDATE.getType());
                    tmp.setCreateTime(lastUpddt);
                    tmp.setLastOprId(user.getId());
                    tmp.setLastUpdateTime(lastUpddt);
                    tmp.setOprMenuId(menuId);
                    tmp.setOprMenuName(oprMenuName);
                    tmp.setOprTableCname("对账不平");
                    tmp.setOprTableEname("T_E_RECON_ERR_TXN");
                    tmp.setManageInstId(user.getOrgCode());
                    tmp.setInstId(user.getInstId());
                    tmp.setBizStatus("00");
                    tmp.setAuditStatus(reconErrTxn.getAuditStatus());
                    if (Common.isBlank(tmp.getRealId())) {
                        tmp.setRealId(uuid);
                    }
                    tmp.setWebNextUrl(webNextUrl);
                    bizTmpService.save(tmp);
                }
//                result.put("id", reconerrtxn.getPrimaryKey());
//                result.put("Status", Status);
            } else {
                reconErrTxn.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                //修改对账不平交易表状态
                LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(ReconErrTxn::getPrimaryKey, primaryKey);
                ReconErrTxn txnUpdate = new ReconErrTxn();
                txnUpdate.setAuditOprId(user.getId());
                txnUpdate.setUpdateTime(lastUpddt);
                txnUpdate.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                txnUpdate.setUpdateTime(lastUpddt);
                this.update(txnUpdate, lambdaQueryWrapper);
                //历史表新增setOrgCode
                bizHisService.saveBizHisNew(reconerrtxnOld, reconErrTxn, user, user.getOrgCode(), BizOprEnum.OPR_UPDATE.getType(), lastUpddt
                        , menuId, oprMenuName, String.valueOf(uuid), null, null, null);
//            result.put("Status", "Y");
//            result.put("instId", reconerrtxn.getInstId());
            }
        } else if (PageOptFlagEnum.OPT_FLAG_CHECK.getType().equals(flag)) {   //审核
            LambdaQueryWrapper<BizTmp> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(BizTmp::getOprTableEname, "T_E_RECON_ERR_TXN");
            BizTmp tmp = bizTmpService.getOne(wrapper);
            if (Common.isBlank(tmp)) {
                String message = "根据id没有找到指定临时表数据!";
                log.info(message);
                throw new RedpException(message);
            }
            String bizdata = "";
            if (null != tmp.getBizData2()) {
                bizdata += tmp.getBizData2();
            }
            if (null != tmp.getBizData3()) {
                bizdata += tmp.getBizData3();
            }
            //临时表数据
            ReconErrTxn reconErrTxnNew = JSON.parseObject(bizdata, ReconErrTxn.class);
            //正式表数据
            ReconErrTxn reconErrTxn = byOrigkey(primaryKey);
            //备份正式表数据
            ReconErrTxn reconErrTxnOld = new ReconErrTxn();
            BeanUtils.copyProperties(reconErrTxn, reconErrTxnOld);
            if (Common.isBlank(reconErrTxn) && !BizOprEnum.OPR_UPDATE.equals(tmp.getBizOpr())) {
                String message = "根据id没有找到指定数据!";
                log.info(message);
                throw new RedpException(message);
            }
            String opt = reconErrTxnVO.getOptFlag();
            if (Common.isBlank(opt)) {
                String message = "请求参数(opt)异常!";
                log.info(message);
                throw new RedpException(message);
            }
            String bizOpr = "";
            BeanUtils.copyProperties(reconErrTxnNew, reconErrTxn);
            String approvalRefuseReason = reconErrTxnVO.getAuditRefuseReason();
            if (PageOptFlagEnum.OPT_FLAG_PASS.getType().equals(opt)) {
                bizOpr = BizOprEnum.OPR_UPDATE.getType();
                //修改审批通过 修改对账不平交易表审核状态为审核通过
                LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(ReconErrTxn::getPrimaryKey, primaryKey);
                ReconErrTxn txnUpdate = new ReconErrTxn();
                txnUpdate.setAuditOprId(user.getId());
                txnUpdate.setUpdateTime(lastUpddt);
                txnUpdate.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType());
                txnUpdate.setUpdateTime(lastUpddt);
                this.update(txnUpdate, lambdaQueryWrapper);
                //审批通过将正式表更新到历史表
                bizHisService.saveBizHisNew(reconErrTxn, reconErrTxnOld, user, user.getOrgCode(), bizOpr, lastUpddt, menuId, oprMenuName, String.valueOf(uuid), null, null, null);
                // 修改临时表的审核状态等字段
                bizTmpService.saveBizTmp(reconErrTxn, user, user.getOrgCode(), bizOpr, lastUpddt, menuId, oprMenuName, "01", BizDataAuditStatusEnum.AUDIT_STATUS_UPD_PASS.getType(), String.valueOf(tmp.getRealId()), webNextUrl, null, null, null);
//                result.put("Status", "Y");
//                result.put("instId", reconerrtxn.getInstId());

            } else {
                bizOpr = BizOprEnum.OPR_UPDATE.getType();
                //修改审批拒绝 修改对账不平交易表审核状态为审核拒绝
                LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                lambdaQueryWrapper.eq(ReconErrTxn::getPrimaryKey, primaryKey);
                ReconErrTxn txnUpdate = new ReconErrTxn();
                txnUpdate.setAuditOprId(user.getId());
                txnUpdate.setAuditRefuseReason(approvalRefuseReason);
                txnUpdate.setUpdateTime(lastUpddt);
                txnUpdate.setAuditStatus(BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType());
                txnUpdate.setUpdateTime(lastUpddt);
                txnUpdate.setAuditStatus("03");
                this.update(txnUpdate, lambdaQueryWrapper);
                // 修改临时表的审核状态等字段
                bizTmpService.saveBizTmp(reconErrTxn, user, user.getOrgCode(), bizOpr, lastUpddt, menuId, oprMenuName, "01", BizDataAuditStatusEnum.AUDIT_STATUS_UPD_REJECT.getType(), String.valueOf(tmp.getRealId()), webNextUrl, null, null, null);
//                result.put("Status", Status);
            }

        }
    }

    /**
     * 调用手工调账接口
     *
     * @param bompManualAdjustAcctService
     * @param user
     * @param primaryKey
     * @param instId
     * @param traceNo
     */
    @Override
    public void manualAdjustment(BompManualAdjustAcctService bompManualAdjustAcctService, UpmpUserInfoVO user, String primaryKey, String instId, String traceNo) throws RedpException {
        ManualAdjustmentRequest req = new ManualAdjustmentRequest();
        req.setHeader(CommonUtils.packageBompHeader(traceNo, BompTxnNumEnum.manualAdjustment.getType(), instId, null));
        req.setUserId(user.getId());
        req.setAdjustUnionKey(primaryKey);
        Map<String, Object> result = com.google.common.collect.Maps.newHashMap();
        log.info("关键域为：" + primaryKey + "，" + BompTxnNumEnum.manualAdjustment.getDesc() + "请求报文：" + JSON.toJSONString(req));
        try {
            Result<ManualAdjustmentResponse> response = bompManualAdjustAcctService.manualAdjustment(req);
            log.info("关键域为：" + primaryKey + "，" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易返回报文：" + JSON.toJSONString(response));
            if (response.isSuccess()) {
                ManualAdjustmentResponse resp = response.getResult();
                // 返回码：00-进件成功，其他均视为失败
                if (BusinessContainer.BSPS_SUCCESS.equals(resp.getRespCode())) {
                    log.info("手工调账" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易成功");
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    String message = BompTxnNumEnum.manualAdjustment.getDesc() + "交易成功";
                    log.info(message);
                } else {
                    result.put("respCode", resp.getRespCode());
                    result.put("respMsg", resp.getRespDesc());
                    log.info("手工调账" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易失败", result);
                    String message = BompTxnNumEnum.manualAdjustment.getDesc() + "交易失败";
                    log.info(message);
                    throw new RedpException(message);
                }
                log.error("关键域为：" + primaryKey + "，" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易没有获得返回信息");
                String message = BompTxnNumEnum.manualAdjustment.getDesc() + "交易失败";
                log.info(message);
                throw new RedpException(message);
            } else {
                log.error("关键域为：" + primaryKey + "，" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易没有获得返回信息");
                String message = BompTxnNumEnum.manualAdjustment.getDesc() + "交易失败";
                log.info(message);
                throw new RedpException(message);
            }
        } catch (Exception e) {
            log.error("关键域为：" + primaryKey + "，" + BompTxnNumEnum.manualAdjustment.getDesc() + "交易出现异常，异常信息：" + e.getMessage(), e);
            String message = BompTxnNumEnum.manualAdjustment.getDesc() + "交易失败";
            log.info(message);
            throw new RedpException(message);
        }
    }

    /**
     * 查询数据
     * @param reconErrTxnVO
     * @return
     */
    @Override
    public Map<String, Object> showData(ReconErrTxnVO reconErrTxnVO) throws RedpException {
        LambdaQueryWrapper<BizTmp> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BizTmp::getOprTableEname, "T_E_RECON_ERR_TXN");
        BizTmp tmp = bizTmpService.getOne(wrapper);
        if (Common.isBlank(tmp)) {
            String message = "根据id没有找到指定临时表数据!";
            log.error(message);
            throw new RedpException(message);
        }
        String bizdata = "";
        if (null != tmp.getBizData2()) {
            bizdata += tmp.getBizData2();
        }
        if (null != tmp.getBizData3()) {
            bizdata += tmp.getBizData3();
        }
        reconErrTxnVO = JSON.parseObject(bizdata, ReconErrTxnVO.class);

        if (Common.isBlank(reconErrTxnVO)) {
            String message = "根据id没有找到指定数据!";
            log.error(message);
            throw new RedpException(message);
        }
        String reconRslt = reconErrTxnVO.getReconRslt();
        if("00".equals(reconRslt)){
            reconRslt = "初始状态";
        }else if("01".equals(reconRslt)){
            reconRslt = "对平或已销账";
        }else if("02".equals(reconRslt)){
            reconRslt = "支付平台无，通道多";
        }else if("03".equals(reconRslt)){
            reconRslt = "支付平台多，通道无";
        }else if("04".equals(reconRslt)){
            reconRslt = "关键要素不一致";
        }else if("05".equals(reconRslt)){
            reconRslt = "重复记账";
        }else if("06".equals(reconRslt)){
            reconRslt = "销账金额不一致";
        }else if("07".equals(reconRslt)){
            reconRslt = "渠道多";
        }else if("08".equals(reconRslt)){
            reconRslt = "对账异常结果";
        }else if("09".equals(reconRslt)){
            reconRslt = "对账正常单边";
        }else if("10".equals(reconRslt)){
            reconRslt = "组合支付场景，对账部分成功";
        }else if("11".equals(reconRslt)){
            reconRslt = "组合支付场景，营销对账部分成功";
        }else if("12".equals(reconRslt)){
            reconRslt = "组合支付场景，支付对账部分成功";
        }else if("20".equals(reconRslt)){
            reconRslt = "银联代付核心1、银联有流水，核心2无流水";
        }else if("21".equals(reconRslt)){
            reconRslt = "银联代付核心1有流水，银联、核心2无流水";
        }else if("22".equals(reconRslt)){
            reconRslt = "银联代付核心1、核心2有流水，银联无流水";
        }else if("23".equals(reconRslt)){
            reconRslt = "银联代付核心1、核心2无流水，银联有流水";
        }else if("24".equals(reconRslt)){
            reconRslt = "银联代付核心1、银联无流水，核心2有流水";
        }else if("25".equals(reconRslt)){
            reconRslt = "银联代付核心1无流水，银联、核心2有流水";
        }else if("26".equals(reconRslt)){
            reconRslt = "银联代收，支付平台有；银联、核心无";
        }else if("27".equals(reconRslt)){
            reconRslt = "银联代收，支付平台、银联有；核心无";
        }else if("28".equals(reconRslt)){
            reconRslt = "银联代收，支付平台、核心有；银联无";
        }else if("30".equals(reconRslt)){
            reconRslt = "D0，通道对账结果有；核心无";
        }else if("31".equals(reconRslt)){
            reconRslt = "D0，通道对账结果无；核心有";
        }else if("**".equals(reconRslt)){
            reconRslt = "不关心对账结果";
        }
        reconErrTxnVO.setReconRslt(reconRslt);
        String adjustStatus = reconErrTxnVO.getAdjustStatus();
        if("00".equals(adjustStatus)){
            adjustStatus = "未调账";
        }else if("01".equals(adjustStatus)){
            adjustStatus = "调账中";
        }else if("02".equals(adjustStatus)){
            adjustStatus = "调账成功";
        }else if("03".equals(adjustStatus)){
            adjustStatus = "调账失败";
        }else if("04".equals(adjustStatus)){
            adjustStatus = "不需要调账";
        }else if("05".equals(adjustStatus)){
            adjustStatus = "调账超时";
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id",reconErrTxnVO.getAcctSeqNum());
        map.put("entity",reconErrTxnVO);
        return map;
    }



    //根据关键域返回对象
    public ReconErrTxn byOrigkey(String primarykey) throws RedpException {
        LambdaQueryWrapper<ReconErrTxn> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        ReconErrTxn reconErrTxn = null;
        if (!Common.isBlank(primarykey)) {
            lambdaQueryWrapper.eq(ReconErrTxn::getPrimaryKey, primarykey);
        } else {
            throw new RedpException("查询对账不平交易表唯一索引列[primary_key]条件为空");
        }
        try {
            reconErrTxn = this.getOne(lambdaQueryWrapper);
        } catch (Exception e) {
            String message = "没有查询到对账不平数据";
            log.info(message);
            return null;
        }
        return reconErrTxn;
    }
}
